package net.hserver.sync.config;

import cn.hserver.core.ioc.annotation.Bean;
import cn.hserver.core.ioc.annotation.Configuration;
import cn.hserver.core.server.context.ConstConfig;
import cn.hserver.plugin.mybatis.flex.bean.MybatisConfig;
import com.zaxxer.hikari.HikariDataSource;

import java.sql.SQLException;

/**
 * @author hxm
 */
@Configuration
public class SqlConfig {
    @Bean
    public MybatisConfig sql() {
        String path = ConstConfig.PATH + "db.db";
        HikariDataSource ds = new HikariDataSource();
        ds.setJdbcUrl("jdbc:sqlite:" + path);
        ds.setDriverClassName("org.sqlite.JDBC");
        MybatisConfig mybatisConfig = new MybatisConfig();
        mybatisConfig.setMapUnderscoreToCamelCase(true);
        //默认数据源
        mybatisConfig.addDataSource(ds);
        //resource/mapper 全部.xml扫描
        mybatisConfig.setMapperLocations("mapper");
        //分页插件
        return mybatisConfig;
    }
}
